import axios from 'axios'
import Element from 'element-ui'
import router from './router'
import store from './store'

// axios.defaults.baseURL="http://localhost:8080"
axios.defaults.baseURL = "http://localhost:8080"

//前置拦截
axios.interceptors.request.use(config =>{
    return config
})

//后置拦截
axios.interceptors.response.use(response =>{
    let res =response.data
    console.log(res)
    return response
},
    error => {
        if(error.response.data){
            error.message=error.response.data.message
        }
        if(error.response.status === 401){
            store.commit("REMOVE_INFO")
            router.push("/login")
        }else{
           this.$message.error(error.message);
            return Promise.reject(error.message);
        }
    }
)